<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Factorial</title>
    <script>
        //循环
        var a = prompt("请输入一个n值");
        function factorial(n){
            var num=1;
            if(n==0||n==1){
                return 1;
            }
            for(var i=1;i<=n;i++){
                num=num*i;
            }
            return num;
        }
        alert(a+"的阶乘结果为:"+factorial(a)); 

        //递归
        /* var b = prompt("请输入一个n值");
        function factorial(n){
            if(n==1||n==0){
                return 1;
            } 
            return n*factorial(n-1);
             
        }
        alert(b+"的阶乘结果为:"+factorial(b)); */

    </script>
</head>
<body>
    
</body>
</html>